package com.ui.mine.presenter;

import com.base.BaseRefreshPresenter;
import com.bean.BaseBean;
import com.bean.LoginBean;
import com.net.ApiService;
import com.net.RetrofitServiceManager;
import com.net.RxResponseObserver;
import com.net.RxSchedulers;
import com.util.ToastUtil;

public class RegisterFragmentPresenter extends BaseRefreshPresenter<RegisterFragmentContract.View> implements RegisterFragmentContract.Presenter {
    @Override
    public void doRegister(String userName, String password, String rePassword) {
        RetrofitServiceManager.getInstance().create(ApiService.class).login(userName, password)
                .compose(RxSchedulers.<BaseBean<LoginBean>>normalSchedulers())
                .compose(mView.<BaseBean<LoginBean>>bindToLife())
                .subscribe(new RxResponseObserver<BaseBean<LoginBean>>() {
                    @Override
                    public void onSuccess(BaseBean<LoginBean> loginBeanBaseBean) {
                        if (loginBeanBaseBean.getData() == null) {
                            //密码错误bean返回null
                            ToastUtil.showToast(loginBeanBaseBean.getErrorMsg());
                        }else {
                            mView.onRegister(loginBeanBaseBean.getData());
                        }
                    }
                });
    }
}

